package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.Favorit;
import top.tsyz.service.IFavoritService;

import java.util.List;

/**
 * FavoritController控制器
 */
@RestController
@RequestMapping("/api/favorites")
@Api(tags = "Favorit管理接口")
public class FavoritController {

    @Autowired
    private IFavoritService ifavoritservice;

    @GetMapping("/list")
    @ApiOperation("获取所有Favorit")
    public List<Favorit> list() {
        return ifavoritservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取Favorit")
    public Favorit getById(@PathVariable Long id) {
        return ifavoritservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增Favorit")
    public boolean save(@RequestBody Favorit favorit) {
        return ifavoritservice.save(favorit);
    }

    @PutMapping
    @ApiOperation("更新Favorit")
    public boolean update(@RequestBody Favorit favorit) {
        return ifavoritservice.updateById(favorit);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除Favorit")
    public boolean delete(@PathVariable Long id) {
        return ifavoritservice.removeById(id);
    }
}
